
package com.example.demo.springmvc;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

@RestController
public class TestController {

    //    @GetMapping("/test")
    @RequestMapping(value="/test", method = {RequestMethod.GET})
    public List<HashMap<String, Object>> test(String name) {

        List<HashMap<String, Object>> hlist = new ArrayList<>();

        HashMap<String, Object> map = new HashMap<>();
        hlist.add(map);
        map.put("name", "zhangsan");
        map.put("age", 18);

        HashMap<String, Object> map1 = new HashMap<>();
        hlist.add(map1);
        map1.put("name", "lisi");
        map1.put("age", 20);
        if (Objects.nonNull(name)){
            List rlist = hlist.stream().filter(x -> x.get("name").equals(name)).toList();
            return rlist;
        } else {
            return hlist;
        }
    }

    @RequestMapping(value="/test", method = {RequestMethod.POST})
    public String test2(Student student) {

        return "post success" + student;
    }

    @PutMapping("/test")
    public String test3(Student student) {

        return "put success" + student;
    }

    @DeleteMapping("/test")
    public String test4(@RequestParam("aaa") String stuid) {

        return "delete success" + stuid;
    }

    // 网站权重
    @GetMapping("{id}/test")
    public String test5(@PathVariable("id") String stuid) {
        return "pathvariable success" + stuid;
    }
}
